package com.example.fang.demodruid.concurrency4;

import java.util.Random;
import java.util.concurrent.CyclicBarrier;

public class MyTest2 {

    public static void main(String[] args){
        //3表示有3个线程参与
        CyclicBarrier cyclicBarrier=new CyclicBarrier(3);

        for(int i=0;i<3;i++){
            new Thread(()->{
                try {
                    Thread.sleep((long)Math.random()*2000);
                    int randomInt=new Random().nextInt(500);
                    System.out.println("hello"+randomInt);
                    cyclicBarrier.await();
                    System.out.println("world"+randomInt);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
